package com.fencing_squad.homo.list;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class Offer {
    String rewardId = "";
    String status = "";
    String content = "";
    String nickname = "";
    String type = "";
    String level = "";
    String toDetail = "";
    String fromDetail = "";
    String img = "";
    String reward = "";
    String fromPos = "";
    String toPos = "";
    String getId = "";

    public Offer() {}

    public Offer(JSONObject object) {
        JSONObject result = object.getJSONObject("result");
        rewardId = result.getString("reward_id");
        content = result.getString("content");
        fromDetail = result.getString("from_detail");
        toDetail = result.getString("to_detail");
        type = result.getString("type");
        level = result.getString("level");
        if (result.getBoolean("has_award")) {
            reward = result.getDoubleValue("money") + "元";
        }
        else {
            reward = result.getIntValue("point") + "分";
        }
        JSONArray imageList = object.getJSONArray("images");
        if (imageList != null && imageList.size() > 0) {
            img = imageList.getString(0);
        }
        toPos = result.getString("to_pos");
        fromPos = result.getString("from_pos");
        status = result.getString("status");
        getId = result.getString("get_id");
    }

    public String getGetId() {
        return getId;
    }

    public void setGetId(String getId) {
        this.getId = getId;
    }

    public String getFromPos() {
        return fromPos;
    }

    public void setFromPos(String fromPos) {
        this.fromPos = fromPos;
    }

    public String getToPos() {
        return toPos;
    }

    public void setToPos(String toPos) {
        this.toPos = toPos;
    }

    public String getReward() {
        return reward;
    }

    public void setReward(String reward) {
        this.reward = reward;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public String getToDetail() {
        return toDetail;
    }

    public void setToDetail(String toDetail) {
        this.toDetail = toDetail;
    }

    public String getFromDetail() {
        return fromDetail;
    }

    public void setFromDetail(String fromDetail) {
        this.fromDetail = fromDetail;
    }

    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }

    public String getRewardId() {
        return rewardId;
    }

    public void setRewardId(String rewardId) {
        this.rewardId = rewardId;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public static List<Offer> getFromJSONArray(JSONArray array) {
        if (array == null) {
            return null;
        }
        ArrayList<Offer> offers = new ArrayList<>();
        for(int i=0; i<array.size(); i++) {
            offers.add(new Offer(array.getJSONObject(i)));
        }
        return offers;
    }
}
